<template>
  <div>
    <el-form :model="editorContent" label-width="100px">
      <el-form-item prop="title" label="文章标题" required>
        <el-input v-model="editorContent.title"></el-input>
      </el-form-item>
      <el-form-item prop="classify" label="分类" required>
        <el-select v-model="editorContent.classify">
          <el-option
            v-for="(item, key) in classify"
            :key="key"
            :value="item.name"
            :label="item.name"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="content" label="文章内容">
        <Quill @content="content" :value="editorContent.content"></Quill>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="editorTrue('editorContent')"
        >确定</el-button
      >
    </div>
  </div>
</template>

<script>
import Quill from "./quill.vue";
export default {
  components: {
    Quill,
  },
  props: {
    editorContent: {
      type: Object,
    },
  },
  data() {
    return {
      classify: {
        name: "",
      },
      value: "",
      contentEdit: "",
    };
  },
  mounted() {
    this.getClassify();
  },
  methods: {
    // 获取分类信息
    getClassify() {
      this.$http.get("/classify").then(
        (res) => {
          this.classify = res.data;
          // console.log(this.classify)
        },
        (err) => {
          console.log(err);
        }
      );
    },
    //修改提交
    editorTrue(editorContent) {
      const data = {
        title: this.editorContent.title,
        classify: this.editorContent.classify,
        content: this.contentEdit,
      };
      console.log(this.contentEdit);

      // 获取 id
      let id = this.editorContent.id;
      console.log(data);
      this.$http.patch(`blog/${id}`, data).then(
        (res) => {
          // 成功提示
          this.$message({
            message: "修改成功！",
            type: "success",
          });
          // 刷新页面
          location.reload();
        },
        (err) => {
          console.log(err);
        }
      );
    },

    //获取富文本内容
    content(value) {
      this.contentEdit = value;
    },
  },
};
</script>

<style scoped>
.el-dialog__body {
  padding: 0 20px;
}
.el-button {
  float: left;
  margin-left: 100px;
}
.el-select {
  float: left;
}
</style>